package com.bawei.composeui2207a.day02

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.bawei.composeui2207a.R

/**
 * 作者：赵亮
 * 时间：2024/12/11 11:56
 * 功能：网格
 */
@Composable
fun Page9() {

    // 数据
    val list = mutableListOf<InfoEntity>()
    repeat(36) {
        list.add(
            InfoEntity(
                R.drawable.zhubajie,
                "猪八戒$it",
                "天蓬元帅"
            )
        )
    }

    // 网格展示
    LazyVerticalGrid(columns = GridCells.Fixed(2)) {
        items(list) {
            Column(modifier = Modifier.padding(5.dp)) {
                Image(
                    modifier = Modifier
                        .fillMaxWidth()
                        .clip(RoundedCornerShape(15.dp)),
                    contentScale = ContentScale.Crop,
                    painter = painterResource(id = it.img),
                    contentDescription = null
                )
                Text(text = it.title)
                Text(text = it.content)
            }
        }
    }
}

@Preview(showSystemUi = true)
@Composable
fun Page9Preview() {
    Page9()
}

